#ifndef OCTREE_H
#define OCTREE_H

#include <iostream>
#include <vector>

#include "cutil_math.h"
#include "radixSort.h"

template <class T>
struct Node
{
	float4 centre;
	int children;
	int num_children;
	T item;
};

class Octree
{

public:

	Node<float4>* d_nodes;
	record_type* d_records;
	int n;
	int depth;


	Octree(int _n, int _depth);
	~Octree();

	void update(float4* d_pos);

	void integrate(float4* d_pos, float4* d_vel, float dt);

	void print(std::vector<float4>& pos);

};

__global__ void initOctree(Node<float4>* nodes, int n);

__global__ void getIndices(float4* pos, record_type* records, int n);

void test();

/*
depth - 1
create octree structure - only need to do once?

has 8^depth nodes
convert float4 to indices of leaf it belongs to
sort indices
bucket indices - look at each pair, and see if different, and assign to octree structure

update octree nodes


to get child, multiply current index by 8 (bit shift by 3) and add 0-7
*/

#endif
